<?php

namespace app\admin\model;

use think\Db;
use app\admin\model\Common;
use think\Session;
use think\Validate;

class  Exedu extends Common
{
   //教育经历添加
   public function WriteExedu($param)
  {
    $info['edu_type']=$param['edu_type'];
    $info['graduated_sch']=$param['graduated_sch'];
    $info['major']=$param['major'];
    $info['graduated_time']=$param['graduated_time'];
    $info['edu_system']=$param['edu_system'];
    $info['degree']=$param['degree'];
    $info['degree_time']=$param['degree_time'];
    $info['degree_sch']=$param['degree_sch'];
    $info['degree_sch_level']=$param['degree_sch_level'];
    $info['degree_sch_nature']=$param['degree_sch_nature'];
    $info['train_id']=$param['train_id'];
    $info['status']=2;
    $info['status1']=2;
    $info['name']=$param['name'];
    $res=Db::table('oa_admin_exedu')
                   ->insert($info);
       if($res){
            return true;
       }else{
       	return false;
       }
  }

  //教育经历列表
  public function ListExedu($param)
  {
     $list=Db::table('oa_admin_exedu')
        ->where('train_id',$param['train_id'])
        ->field('id,edu_type,graduated_sch,major,graduated_time,edu_system,degree,degree_time,degree_sch,degree_sch_level,degree_sch_nature,status')
        ->select();
     return $list;
  }
  //教育经历修改
   public function ReviseExedu($param)
  {
    $id=$param['id'];
    $info['edu_type']=$param['edu_type'];
    $info['graduated_sch']=$param['graduated_sch'];
    $info['major']=$param['major'];
    $info['graduated_time']=$param['graduated_time'];
    $info['edu_system']=$param['edu_system'];
    $info['degree']=$param['degree'];
    $info['degree_time']=$param['degree_time'];
    $info['degree_sch']=$param['degree_sch'];
    $info['degree_sch_level']=$param['degree_sch_level'];
    $info['degree_sch_nature']=$param['degree_sch_nature'];
    $info['updata_time']=date('Y-m-d');
    $status=Db::table('oa_admin_exedu')
            ->where('id',$id)
            ->field('status')
            ->select();
         if($status[0]['status']=='2')
          {
            $info['status']=4;
            $info['ps']='教育经历'; 
          }if($status[0]['status']=='3'){
            $info['status']=1; 
          }if($status[0]['status']=='1'){
            $info['status']=1; 
          }
         $res= Db::table('oa_admin_exedu')
          ->where('id',$id)
          ->find();
     if($res){
         Db::table('oa_admin_exedu')
          ->where('id',$id)
          ->update([
            'edu_type'=> $info['edu_type'],
            'graduated_sch'=>$info['graduated_sch'],
            'major'=>$info['major'],
            'graduated_time'=>$info['graduated_time'],
            'edu_system'=>$info['edu_system'],
            'degree'=>$info['degree'],
            'degree_time'=>$info['degree_time'],
            'degree_sch'=>$info['degree_sch'],
            'degree_sch_level'=>$info['degree_sch_level'],
            'degree_sch_nature'=>$info['degree_sch_nature'],
            'status'=> $info['status'],
            'updata_time'=>$info['updata_time'],
            'ps'=>$info['ps'],
          ]);

           return true;
          }else{
          	return false;
          }
  }
  //教育经历删除
    public function DeleteExedu($param)
    {
    	$id=$param['id'];
    	$res= Db::table('oa_admin_exedu')
          ->where('id',$id)
          ->delete();
          if($res){
          	return true;
          }else{
          	return false;
          }
    }
}